package data.objects;

import java.util.List;
import java.util.UUID;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIgnore;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;

import data.dynamodbfunctions.Persistence_Helper_User;
import data.exceptions.Dynamo_DB_Functions_Exception;
import data.meta.Metadata;
import data.meta.MetaAnnotations.MetaMethod;
import data.meta.MetaAnnotations.MetaParam;

@DynamoDBTable(tableName="CC_User")
public class User {
	
	public String ID;	
	public String Lastname;
	public String Firstname;
	public String TenantID;
	
	
	public User(String tenantID, String vorname, String nachname) {
		super();
		TenantID = tenantID;
		ID = ""+UUID.randomUUID();
		Firstname = vorname;
		Lastname = nachname;
	}
	public User(){
		ID = ""+UUID.randomUUID();
	}
	
	@DynamoDBHashKey(attributeName="ID")
	public String getTenantID() {return TenantID;}
	public void setTenantID(String tenantID) {TenantID = tenantID;}
	
	@DynamoDBRangeKey(attributeName="Range_ID")
	public String getID() {return ID;}	
	public void setID(String iD) {ID = iD;}
	
	@DynamoDBAttribute(attributeName="Vorname")
	public String getVorname() {return Firstname;}	
	public void setVorname(String vorname) {Firstname = vorname;}
	
	@DynamoDBAttribute(attributeName="Nachname")
	public String getNachname() {return Lastname;}
	public void setNachname(String nachname) {Lastname = nachname;}
	
	@MetaMethod
	@DynamoDBIgnore
	public static User create(@MetaParam("TenantID") String tenantID,@MetaParam("Firstname") String vorname,@MetaParam("Lastname") String nachname) throws Dynamo_DB_Functions_Exception {
		User object = new User(tenantID, vorname,nachname);
		return Persistence_Helper_User.getInstance().create(object);	
	}
	@DynamoDBIgnore
	public static User read(String tenant_id, String id) throws Dynamo_DB_Functions_Exception {
		User readobject=Persistence_Helper_User.getInstance().read(tenant_id,id);
		return readobject;
	}
	@DynamoDBIgnore
	public static List<User> read(String tenant_id) throws Dynamo_DB_Functions_Exception {
		List<User> readobject=Persistence_Helper_User.getInstance().readAllwithHashKey(tenant_id);
		return readobject;
	}
	
	@DynamoDBIgnore
	public static User update(String tenant_id, String ID, String vorname,String nachname) throws Dynamo_DB_Functions_Exception {
		User object =Persistence_Helper_User.getInstance().read(tenant_id,ID);
		if(!"".equals(vorname)){
			object.setVorname(vorname);
		}
		if(!"".equals(nachname)){
			object.setNachname(nachname);
		}
		return Persistence_Helper_User.getInstance().update(object);
	}
	
	@DynamoDBIgnore
	public static User delete(String tenant_id, String id) throws Dynamo_DB_Functions_Exception {
		return Persistence_Helper_User.getInstance().delete(tenant_id,id);
	}
	
	@DynamoDBIgnore
	public static Metadata getMetadata(){
		return ClassSpy.getMetadata("data.objects.User");
	}
	
}
